package appVersionRecord

import (
	"context"
	"errors"
	"github.com/google/uuid"
	"insighttracking/query/model"
	"insighttracking/query/service"
	"net/http"

	"insighttracking/apps/admin/internal/svc"
	"insighttracking/apps/admin/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
	"os"
)

type CreateAppVersionRecordApiLogic struct {
	logx.Logger
	ctx     context.Context
	svcCtx  *svc.ServiceContext
	Request *http.Request
}

func NewCreateAppVersionRecordApiLogic(ctx context.Context, svcCtx *svc.ServiceContext, request *http.Request) *CreateAppVersionRecordApiLogic {
	hostname, _ := os.Hostname()
	return &CreateAppVersionRecordApiLogic{
		Logger: logx.WithContext(ctx).WithCallerSkip(0).WithFields(
			logx.Field("Log_UUID", uuid.New().String()),
			logx.Field("hostname", hostname)),
		ctx:     ctx,
		svcCtx:  svcCtx,
		Request: request,
	}
}

func (l *CreateAppVersionRecordApiLogic) CreateAppVersionRecordApi(req *types.CreateAppVersionRecordReq) (resp string, err error) {
	if err = service.AppVersionRecordService.CreateApi(l.ctx, &model.AppVersionRecordEntity{
		Version:  req.Version,  // 版本号
		FileURL:  req.FileURL,  // 文件地址
		FileName: req.FileName, // 文件名称
		Md5:      req.Md5,      // MD5的值
		Types:    req.Types,    // app版本类型,0表示分拣，1表示门店,2表示采购
		Remark:   req.Remark,   // 备注
	}); err != nil {
		return "", errors.New("创建失败")
	}
	return "操作成功", nil
}
